package com.purong.purong.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.purong.purong.R;
import com.purong.purong.bean.BankBean;
import com.purong.purong.widget.RadiusImageView;
import com.yao.sdk.glide.GlideUtil;

/**
 * Circle Photo 列表的数据适配器
 */
public class BankRecyAdapter extends HeadRecycleAdapter<BankBean,BankRecyAdapter.ViewHolder> {



    private Context mContext;
    private OnBankClickListener mListener;
    public BankRecyAdapter(Context context) {
        this.mContext = context;
    }
    public void setOnBankClickListener(OnBankClickListener listener){
        this.mListener=listener;
    }


    /**
     * 通过ViewHolder可以访问每个item的所有控件
     */
    public static class ViewHolder extends RecyclerView.ViewHolder {
        //绑定每个CircleItem的控件引用到ViewHolder
       private RadiusImageView image;
        private TextView name;
        private LinearLayout mainLay;
        public ViewHolder(View v) {
            super(v);
            image = (RadiusImageView)v.findViewById(R.id.bank_image);
            name = (TextView)v.findViewById(R.id.bank_name);
            mainLay=(LinearLayout)v
                    .findViewById(R.id.main_lay);



        }
    }



    @Override
    public RecyclerView.ViewHolder onCreateView(ViewGroup parent) {
        View  v = LayoutInflater.from(parent.getContext())
                .inflate(R.layout.credit_bank_item, parent, false);
        ViewHolder vh = new ViewHolder(v);
        return vh;
    }

    @Override
    public void onBindView(ViewHolder mHolder, final BankBean data, final int position) {
        mHolder.mainLay.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (mListener!=null){
                    mListener.onBankClick(data);
                }
            }
        });
        if (data.getBank_name()!=null)
            mHolder.name.setText(data.getBank_name());
        GlideUtil.getInstance().load(mContext, data.getBank_url(), mHolder.image,true);
    }






    public interface OnBankClickListener{
        void onBankClick(BankBean bank);
    }
}


